package CH01数组结构.LeetCode双指针;

public class LC718 {
    public int findLength(int[] nums1, int[] nums2) {
        int maxLen = 0;
        for (int i = nums1.length - 1; i >= 0; i--) {
            int len = 0;
            int p1 = i;
            int p2 = 0;
            while (p1 < nums1.length && p2 < nums2.length) {
                if (nums1[p1] == nums2[p2]) {
                    len++;
                    maxLen = Math.max(len,maxLen);
                } else {
                    len = 0;
                }
                p1++;
                p2++;
            }
        }
        for (int i = 1; i < nums2.length; i++) {
            int len = 0;
            int p1 = 0;
            int p2 = i;
            while (p1 < nums1.length && p2 < nums2.length) {
                if (nums1[p1] == nums2[p2]) {
                    len++;
                    maxLen = Math.max(len,maxLen);
                } else {
                    len = 0;
                }
                p1++;
                p2++;
            }
        }
        return maxLen;
    }
}